//https://leetcode-cn.com/problems/roman-to-integer/
class Solution {
public:
    int getValue(char ch) {
        switch (ch) {
            case 'I': return 1;
            case 'V': return 5;
            case 'X': return 10;
            case 'L': return 50;
            case 'C': return 100;
            case 'D': return 500;
            case 'M': return 1000;
        }
        return  0;
    }

    int romanToInt(string s) {
        int num = 0;
        for (int i = 0; s[i]; i++) {
            num += getValue(s[i]);
            if (i && getValue(s[i]) > getValue(s[i - 1])) {
                num -= 2 * getValue(s[i - 1]);
            }
        }
        return num;
    }
};